﻿Module common
    Public dbConn As New OleDb.OleDbConnection
    Public dbConnSQL As New OleDb.OleDbConnection
    Public dbSrc As String
    Public gVerNo As String = "1.4"
    Public gVersion As String = "현재 Ver. " + gVerNo
    Public gLatestVersion As String
    Public gWeekFlag As Boolean = False
    Public gLatestVer As String
    Public os As OperatingSystem = Environment.OSVersion

    Public Sub dbSqlConnection()
        dbSrc = "provider=sqloledb;server=inventory.jadesoft.co.kr;database=noahtech;uid=noahtech;pwd=shdkxpr7;"
        'MsgBox(dbSrc)
        dbConnSQL.ConnectionString = dbSrc
        dbConnSQL.Open()
    End Sub

    '## 쿼리에 대한 하나의 값 반환하기
    Public Function gSqlAFieldValue(ByVal query As String) As String

        Call dbSqlConnection()
        Dim dsCommon As DataSet
        Dim daCommon As OleDb.OleDbDataAdapter
        Dim rtnValue As String
        dsCommon = New DataSet
        daCommon = New OleDb.OleDbDataAdapter(query, dbConnSQL)
        daCommon.Fill(dsCommon, "aFieldValue")

        dbConnSQL.Close()
        rtnValue = dsCommon.Tables("aFieldValue").Rows(0).Item(0)

        Return rtnValue
    End Function

    Public Sub gSubSaveAction(ByVal query As String, ByVal msg As String)

        Call dbSqlConnection()
        Dim oleCmd As OleDb.OleDbCommand
        Dim oleTran As OleDb.OleDbTransaction
        oleCmd = New OleDb.OleDbCommand(query, dbConnSQL)

        oleTran = dbConnSQL.BeginTransaction
        oleCmd.Transaction = oleTran
        Try

            oleCmd.ExecuteNonQuery()
            oleTran.Commit()

            If msg <> "" Then
                MsgBox(msg)
            End If
            dbConnSQL.Close()
        Catch err As OleDb.OleDbException
            oleTran.Rollback()
            dbConnSQL.Close()
            MsgBox(query)

            MsgBox(err.Message, MsgBoxStyle.Critical, "오류")
        End Try
    End Sub

    '## 맥 어드레스 구하기
    Public Function getMacAddr() As String
        Dim nics() As System.Net.NetworkInformation.NetworkInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
        Return nics(0).GetPhysicalAddress.ToString
    End Function

End Module
